package com.test;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class TCyclicBarrier {
    public static void main(String[] args) {
        CyclicBarrier haha = new CyclicBarrier(3);
        int x=3;
        while(x>0){
            x--;
            int fx = x;
            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        haha.await();
                        for(int i=1;i<10;i++){
                            System.out.println("t:"+fx+" "+i);
                            Thread.sleep(1000);
                        }
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    } catch (BrokenBarrierException e) {
                        throw new RuntimeException(e);
                    }

                }
            });
            t.start();
        }
        try {
            Thread.sleep(1000*15);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
